package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.*;
import gentle.factory.PageFactory;
import gentle.service.ITcRevisitService;
import gentle.support.DateTimeKit;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * tctc回访
 *
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@RestController
@RequestMapping("tcRevisit")
public class TcRevisitController extends BaseController {
    @Autowired
    ITcRevisitService revisitService;

    /**
     * TC回访列表加载
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object tcInfoList(SearchTcRevisitInfo info ) {
        if(info.getAbbreviation() ==null || info.getAbbreviation() == "" || info.getAbbreviation() =="null"){
            return null;
        }else{
            Page<TcRevisitInfo> page = new PageFactory<TcRevisitInfo>().defaultPage();
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<TcRevisitInfo> list = revisitService.selectPageListByRevisit(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = revisitService.selectPageListByRevisit(page, info);
                }
                page.setTotal(revisitService.getQueryPagesRevisitCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

    /**
     * TC回访列表统计查询
     */
    @RequestMapping(value = "/total", method = RequestMethod.GET)
    @ResponseBody
    public List<TongJiInfo> total(String reach, String startRevisitTime, String startTime, String endTime, String startUpdateTime, String endUpdateTime, String followStatus, String consumptionStatus,
                                  String endRevisitTime, String revisit, String outpatientName, String abbreviation) throws Exception {
        return revisitService.total(reach, startRevisitTime,startTime,endTime,startUpdateTime,endUpdateTime,followStatus,consumptionStatus,
                endRevisitTime,revisit,outpatientName,abbreviation);
    }

    //回访记录table数据列表
    @RequestMapping(value = "/TcFollowTableList/{reservationsId}/{abbreviation}")
    @ResponseBody
    public List<TcRevisitsInfo> TcFollowTableList(@PathVariable String reservationsId,@PathVariable String abbreviation) throws Exception {
        return revisitService.TcFollowTableList(reservationsId,abbreviation);
    }

    //回访待计划
    @RequestMapping(value = "/addTcContent2", method = RequestMethod.POST)
    @ResponseBody
    public int addTcContent2(String customerId,String followStatus, String consumptionStatus, String revisitContent, String revisitTime,
                             String remarks, String reservationsId, String revisit,String abbreviation, String userName, String outpatientName) {
        return revisitService.addTcContent2(customerId,followStatus,consumptionStatus,revisitContent,revisitTime,remarks,reservationsId,
                revisit,abbreviation,userName,outpatientName);
    }

    //回访完成
    @RequestMapping(value = "/addTcContentOver", method = RequestMethod.POST)
    @ResponseBody
    public int addTcContentOver(String customerId,String followStatus, String consumptionStatus, String revisitContent, String revisitTime,
                                String remarks, String reservationsId, String revisit,String abbreviation, String userName, String outpatientName) {
        return revisitService.addTcContentOver(customerId,followStatus,consumptionStatus,revisitContent,revisitTime,remarks,reservationsId,
                revisit,abbreviation,userName,outpatientName);
    }

    //删除tc回访
    @RequestMapping(value = "/delete_tcFollow", method = RequestMethod.POST)
    @ResponseBody
    public int delete_tcFollow(String ids) throws Exception {
        return revisitService.delete_tcFollow(ids);
    }

    //修改tc回访 待计划
    @RequestMapping(value = "/updateTcContent", method = RequestMethod.POST)
    @ResponseBody
    public int updateTcContent(String tcName, String createName,String followStatus, String consumptionStatus,String revisitTime,
                               String revisitContent, String tcVisitId, String remarks, String reservationsId,String revisit,String abbreviation) {
        return revisitService.updateTcContent(tcName,createName,followStatus,consumptionStatus,revisitTime,revisitContent,tcVisitId,
                remarks,reservationsId,revisit,abbreviation);
    }

    //修改tc回访 回访完成
    @RequestMapping(value = "/updateTcContent1", method = RequestMethod.POST)
    @ResponseBody
    public int updateTcContent1(String tcName, String createName,String followStatus, String consumptionStatus,String revisitTime,
                                String revisitContent, String tcVisitId,String remarks, String reservationsId, String revisit,String abbreviation) {
        return revisitService.updateTcContent1(tcName,createName,followStatus,consumptionStatus,revisitTime,revisitContent,tcVisitId,
                remarks,reservationsId,revisit,abbreviation);
    }

    //修改tc回访 取消回访
    @RequestMapping(value = "/updateTcContent2", method = RequestMethod.POST)
    @ResponseBody
    public int updateTcContent2(String tcName, String createName,String followStatus, String consumptionStatus,String revisitTime,
                                String revisitContent, String tcVisitId,String remarks, String reservationsId, String revisit,String abbreviation) {
        return revisitService.updateTcContent2(tcName,createName,followStatus,consumptionStatus,revisitTime,revisitContent,tcVisitId,
                remarks,reservationsId,revisit,abbreviation);
    }

    //查询tc回访内容模板
    @RequestMapping(value = "/getSfById", method = RequestMethod.POST)
    @ResponseBody
    public SfInfo getSfById(String id) {
        return revisitService.getSfById(id);
    }

    //查询tc回访结果模板
    @RequestMapping(value = "/getJgById", method = RequestMethod.POST)
    @ResponseBody
    public SfInfo getJgById(String id) {
        return revisitService.getJgById(id);
    }

    //删除tc回访内容模板
    @RequestMapping(value = "/deleteSfById", method = RequestMethod.POST)
    @ResponseBody
    public int deleteSfById(String id) throws Exception {
        return revisitService.deleteSfById(id);
    }

    //删除tc回访结果模板
    @RequestMapping(value = "/deleteJgById", method = RequestMethod.POST)
    @ResponseBody
    public int deleteJgById(String id) throws Exception {
        return revisitService.deleteJgById(id);
    }

}